package com.white.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.white.bean.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    String TABLE_NAME = " comment ";
    String SELECT = "select * from" + TABLE_NAME + "where ";
    int LIMIT = 10;
    String CREATE_TIME = " createTime ";
    String ORDER_BY = " order by " + CREATE_TIME + "desc";

    @Select(SELECT + "articleId = #{articleId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<Comment> getCommentByArticleId(Long articleId);
    @Select("select * from comment c where c.commentId in(select replyCommentId from comment c, reply r where c.commentId = r.beReplyCommentId and beReplyCommentId = #{commentId}) order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<Comment> getReplies(Long commentId);

    @Select("select * from comment where articleId = #{articleId} and userId = #{userId} and articleId = #{articleId} and content = #{content} " + ORDER_BY + " limit 1")
    Comment getOne(Comment comment);

    @Select(SELECT + "userId = #{userId} order by " + CREATE_TIME + " desc limit " + LIMIT)
    List<Comment> getCommentByUserId(Long userId);
}
